package rj.servlet.chapter03;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;

@WebServlet("/ShowLetter")
public class ShowLetter extends GenericServlet {

    @Override
    public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
        // 设置响应内容类型
        res.setContentType("text/html;charset=UTF-8");

        // 获取 PrintWriter 对象，用于向客户端发送数据
        PrintWriter out = res.getWriter();

        // 输出 HTML 内容
        out.println("<html>");
        out.println("<head>");
        out.println("<title>英文字母表</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>英文字母表</h1>");

        // 显示大写字母表
        out.println("<h2>大写字母表</h2>");
        out.println("<ul>");
        for (char c = 'A'; c <= 'Z'; c++) {
            out.println("<li>" + c + "</li>");
        }
        out.println("</ul>");

        // 显示小写字母表
        out.println("<h2>小写字母表</h2>");
        out.println("<ul>");
        for (char c = 'a'; c <= 'z'; c++) {
            out.println("<li>" + c + "</li>");
        }
        out.println("</ul>");

        out.println("</body>");
        out.println("</html>");

        // 刷新并关闭 PrintWriter 对象
        out.flush();
    }
}
